﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
//#JMJ Create_20241102

namespace IHateWorking.Model
{
    public class Converter_Bool2VisibleOrCollapsed : IValueConverter
    {
        /// <summary>
        /// 根据控件的开关值来返回控件的显示/折叠状态
        /// </summary>
        /// <param name="value">控制控件显示/折叠状态的开关值</param>
        /// <param name="targetType"></param>
        /// <param name="parameter">有参数既视为置逆</param>
        /// <param name="culture"></param>
        /// <returns>折叠/显示</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                return parameter == null
                    ? System.Convert.ToBoolean(value) ? Visibility.Visible : Visibility.Collapsed//不置逆：value 为 true 显示
                    : (object)(System.Convert.ToBoolean(value) ? Visibility.Collapsed : Visibility.Visible);//置逆：value 为 true 隐藏
            }
            catch (Exception e)
            {
                string ex = e.ToString();
                return Binding.DoNothing;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
}
